// pages/success/success.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    receiver:'',
    mobile:'',
    address:''
  },
goShop(){
wx.switchTab({
  url: '/pages/home/home',
})
},


goOrder(){
  wx.navigateTo({
    url: '/pages/myOrder/myOrder',
  })
  },
  // 计算总价格
  getTotal(){
    // 计算总价格
    let goodsList = this.data.goodsList;

    if(goodsList.length){
        let data = goodsList.reduce((total,item)=>{
            total = total + item.num * item.goodsPrice;
            return total;
        },0)

        
        this.setData({
            totalData:data
        })
    }
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   let receiver = wx.getStorageSync('receiver')
   let mobile =wx.getStorageSync('mobile')
   let address =wx.getStorageSync('address')
   this.setData({
    receiver:receiver,
    mobile:mobile,
    address:address
   })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
          // 获取缓存数据
          var getCardata = wx.getStorageSync('GoodsCarList');

          this.setData({
              goodsList: getCardata,
          })
    this.getTotal()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.reLaunch({
      url: '/pages/home/home',
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})